package com.example.elemboot.Controller;

import com.example.elemboot.Dao.IBusiness;
import com.example.elemboot.Entity.Business;
import com.example.elemboot.Utils.AuthAccess;
import com.example.elemboot.Utils.Result;
import com.example.elemboot.Vo.UserVO;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/business")
public class BusinessController {
    @Resource
    private IBusiness businessDao;


    //获取商家列表
    @GetMapping(value = "/getBusinesses")
    public Result getAllBusiness(@RequestParam String kw){
        try {
            Iterable<Business> businesses = businessDao.findBusinessesByBusinessNameContaining(kw);
            return Result.success(businesses);
        }catch (Exception e){
            return Result.error();
        }

    }

    //根据点餐分类编号查询所属商家信息
    @GetMapping(value = "/getBusinessesByOrderTypeId/{orderTypeId}")
    public Result getBusinessesByOrderTypeId(@PathVariable("orderTypeId") Integer orderTypeId){
        try {
            Iterable<Business> businesses = businessDao.findBusinessesByOrderTypeIdEquals(orderTypeId);
            return Result.success(businesses);
        }catch (Exception e){
            return Result.error();
        }
    }

    @GetMapping(value = "/getBusinessById/{businessId}")
    public Result getBusinessById(@PathVariable("businessId") Integer businessId){
        try {
            Business business = businessDao.findById(businessId).get();
            return Result.success(business);
        }catch (Exception e){
            return Result.error();
        }
    }
}
